package org.litespring.context.support;

import org.litespring.beans.factory.support.DefaultBeanFactory;
import org.litespring.beans.factory.xml.XmlBeanDefinitionReader;
import org.litespring.context.ApplicationContext;
import org.litespring.core.io.FileSystemResource;
import org.litespring.core.io.Resource;

/**
 * Create by leonardo on 2018/8/26
 */
public class FileSystemXmlApplicationContext implements ApplicationContext {

    private DefaultBeanFactory factory = null;

    //封装读取配置文件过程
    public FileSystemXmlApplicationContext(String config) {
        factory = new DefaultBeanFactory();
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        Resource resource = new FileSystemResource(config);
        reader.loadBeanDefinitions(resource);
    }

    //获取bean
    public Object getBean(String beanID) {
        return factory.getBean(beanID);
    }


}
